<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" charset="utf-8" src="CommonUtil/CommonUtil.js"></script>
    <script type="text/javascript" charset="utf-8">
        //搭建一个工厂环境
        //买车的商店
        function CarShop() {
        }
        CarShop.prototype = {
            constructor:CarShop,
            sellCar:function (type) {
                //申明一个变量
                var car;
                switch (type){
                    case 'Benz':
                        car = new Benz();
                        break;
                    case 'Bmw':
                        car = new Bmw();
                        break;
                    case 'Audi':
                        car = new Audi();
                        break;
                    default: 'not buy it';
                        break;
                }
                BH.Interface.ensureImplements(car,CarInterface);
                return car;
            }
        }

        //Class benz,bmw,audi;
        var CarInterface = new BH.Interface('CarInterface',['start','run']);
        //超类 superClass()
        function BaseCar() {
        };
        BaseCar.prototype = {
            constructor:BaseCar,
            start:function () {
                alert(this.constructor.name+'...start...');
            },
            run:function () {
                alert(this.constructor.name+'...run...');
            }
        };
        function Benz() {
        }
        BH.extend(Benz,BaseCar);
        Benz.prototype.driveBenz = function () {
            alert('drive Benz...');
        }
        function Bmw() {
        }
        BH.extend(Bmw,BaseCar);
        Bmw.prototype.deiveBmw= function () {
            alert('drive Bwm...');
        }
        function Audi() {
        }

        /**
         * 子类先继承父类，然后子类再去扩展子类特有的方法。
         */
        BH.extend(Audi,BaseCar);
        Audi.prototype.driveAudi = function () {
            alert('drive Audi...');
        }
        var shop = new CarShop();
        var car=shop.sellCar('Benz');
        car.start();
        car.run();
        car.driveBenz();
    </script>
</head>
<body>
</body>
</html>